package com.park.service.impl.resource;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.park.client.model.resource.ResourceCommentModel;
import com.park.client.service.resource.ResourceCommentService;
import com.park.common.util.Page;
import com.park.common.util.PageData;
import com.park.dao.resource.ResourceCommentMapper;
import com.park.service.impl.base.BaseServiceImpl;

@Service("resourceCommentService")
public class ResourceCommentServiceImpl extends BaseServiceImpl<ResourceCommentModel> implements ResourceCommentService {
	
	@Autowired
	private  ResourceCommentMapper  resourceCommentMapper;

	@Override
	public boolean deleteByPrimaryKey(Long id) {
		return resourceCommentMapper.deleteByPrimaryKey(id)==1;
	}
	
	@Override
	public boolean insertSelective(ResourceCommentModel record) {
		return resourceCommentMapper.insertSelective(record)==1;
	}
	
	@Override
	public ResourceCommentModel selectByPrimaryKey(Long id) {
		return resourceCommentMapper.selectByPrimaryKey(id);
	}
	@Override
	public boolean updateByPrimaryKeySelective(ResourceCommentModel record) {
		return resourceCommentMapper.updateByPrimaryKeySelective(record)==1;
	}
	
	@Override
	public boolean updateByPrimaryKey(ResourceCommentModel record) {
		return resourceCommentMapper.updateByPrimaryKey(record)==1;
	}
	
	@Override
	public boolean insert(ResourceCommentModel record) {
		return resourceCommentMapper.insert(record)==1;
	}
	
	@Override
	public List<ResourceCommentModel> selectAll() {
		return resourceCommentMapper.selectAll();
	}
	
	@Override
	public ResourceCommentModel selectIsExist(ResourceCommentModel record) {
		return resourceCommentMapper.selectIsExist(record);
	}
	
	@Override
	public Integer selectAvgScore(Long resourceId) {
		return resourceCommentMapper.selectAvgScore(resourceId);
	}
	
	@Override
	public List<ResourceCommentModel> selectPagination(ResourceCommentModel t) {
		return this.resourceCommentMapper.selectPagination(t);
	}
	
	@Override
	public Integer selectTotal(ResourceCommentModel t) {
		return this.resourceCommentMapper.selectTotal(t);
	}

	@Override
	public PageData<ResourceCommentModel> commentList(ResourceCommentModel commentModel) {
		PageData<ResourceCommentModel>  pageData = new PageData<>();
		Integer total = this.resourceCommentMapper.selectTotal(commentModel);
		Page page = new Page(1,total,20);
		commentModel.setStartPos(page.getStartPos());
		commentModel.setPageSize(page.getPageSize());
		List<ResourceCommentModel> list = this.resourceCommentMapper.selectPagination(commentModel);
		pageData.setTotal(total);
		pageData.setRows(list);
		return pageData;
	}

}
